package com.zhucezmf.activemqtestdemo.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@EnableScheduling
@Component
public class Porducer {

    private final JmsTemplate jmsTemplate;

    @Autowired
    public Porducer(JmsTemplate jmsTemplate) {
        this.jmsTemplate = jmsTemplate;
    }

    @Scheduled(fixedDelay = 1000)//每3s执行1次,将消息放入队列内
    public void sendTextMessage() {

        this.jmsTemplate.convertAndSend("zhucezmf.mq.test.queue3",
                "测试消息队列" + System.currentTimeMillis() / 1000);
    }
}
